package com.atguigu.lease.web.app.service.impl;

import com.atguigu.lease.model.entity.*;
import com.atguigu.lease.model.enums.ItemType;
import com.atguigu.lease.web.app.mapper.*;
import com.atguigu.lease.web.app.service.ApartmentInfoService;
import com.atguigu.lease.web.app.service.GraphInfoService;
import com.atguigu.lease.web.app.vo.apartment.ApartmentDetailVo;
import com.atguigu.lease.web.app.vo.apartment.ApartmentItemVo;
import com.atguigu.lease.web.app.vo.graph.GraphVo;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.List;

/**
 * @author liubo
 * @description 针对表【apartment_info(公寓信息表)】的数据库操作Service实现
 * @createDate 2023-07-26 11:12:39
 */
@Service
public class ApartmentInfoServiceImpl extends ServiceImpl<ApartmentInfoMapper, ApartmentInfo>
        implements ApartmentInfoService {
    @Autowired
    GraphInfoMapper graphInfoMapper;
    @Autowired
    LabelInfoMapper labelInfoMapper;
    @Autowired
    RoomInfoMapper roomInfoMapper;
    @Autowired
    FacilityInfoMapper facilityInfoMapper;

    @Override
    public ApartmentItemVo getApartInfo(Long id) {
        ApartmentItemVo apartmentItemVo = new ApartmentItemVo();

        //查询房间所属公寓的基本信息
        ApartmentInfo apartmentInfo = getById(id);

        //公寓的图片
        List<GraphVo> graphInfo = graphInfoMapper.getGraphInfo(ItemType.APARTMENT,id);
        List<GraphInfo> graphInfoList = new ArrayList<>();
        for (GraphVo graphVo : graphInfo) {
            GraphInfo graphInfo1 = new GraphInfo();
            graphInfo1.setName(graphVo.getName());
            graphInfo1.setUrl(graphVo.getUrl());
            graphInfoList.add(graphInfo1);
        }

        //公寓的标签
        List<LabelInfo> labelInfoList = labelInfoMapper.getApartLabelInfo(id);

        //最小租金
        BigDecimal minRent = roomInfoMapper.getMinRent(id);

        BeanUtils.copyProperties(apartmentInfo, apartmentItemVo);

        apartmentItemVo.setGraphVoList(graphInfoList);
        apartmentItemVo.setLabelInfoList(labelInfoList);
        apartmentItemVo.setMinRent(minRent);



        return apartmentItemVo;
    }

    @Override
    public ApartmentDetailVo getApartmentDetailById(Long id) {
        ApartmentDetailVo apartmentDetailVo = new ApartmentDetailVo();
        //查询公寓基本信息
        ApartmentInfo apartmentInfo = getById(id);

        //公寓配套
        List<FacilityInfo> facilityInfoList = facilityInfoMapper.getApartFacilityInfo(id);

        //公寓标签
        List<LabelInfo> labelInfoList = labelInfoMapper.getApartLabelInfo(id);

        //公寓图片
        List<GraphVo> graphVoList = graphInfoMapper.getGraphInfo(ItemType.APARTMENT,id);

        //公寓最低租金
        BigDecimal minRent = roomInfoMapper.getMinRent(id);


        BeanUtils.copyProperties(apartmentInfo,apartmentDetailVo);

        apartmentDetailVo.setFacilityInfoList(facilityInfoList);
        apartmentDetailVo.setLabelInfoList(labelInfoList);
        apartmentDetailVo.setGraphVoList(graphVoList);
        apartmentDetailVo.setMinRent(minRent);

        return apartmentDetailVo;
    }
}




